# First stage: complete build environment
FROM maven:3.5.0-jdk-8-alpine AS builder

COPY ./settings.xml /root/.m2/

# add pom.xml and source code
ENV MY_HOME=/usr/src/app
RUN mkdir -p $MY_HOME
WORKDIR $MY_HOME
ADD ./supply-provider $MY_HOME

# package jar
RUN mvn clean package -U -Dmaven.test.skip=true

# Second stage: minimal runtime environment
From openjdk:8-jre-alpine

# copy jar from the first stage
COPY --from=builder /usr/src/app/target/supply-provider-1.0-SNAPSHOT.jar supply-provider-1.0-SNAPSHOT.jar

EXPOSE 9011

CMD ["java", "-jar", "supply-provider-1.0-SNAPSHOT.jar"]